/*
 * FileName：SysJobCtrl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.primary.sys.ctrl;

import com.smart.common.BaseCtrl;
import com.smart.common.util.AjaxResult;
import com.smart.quartz.entity.JobEntity;
import com.smart.quartz.service.IJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hermit
 * @version 2.0
 * @date 2018-12-17 10:54:58
 */
@RestController
@RequestMapping("/sys/job")
@Api(description = "定时任务")
public class SysJobCtrl extends BaseCtrl {
    @Autowired
    private IJobService jobService;


    /**
     * 所有任务
     *
     * @return
     */
    @GetMapping("list")
    @ApiOperation(value = "获取所有任务信息")
    public AjaxResult listJob(JobEntity jobEntity) throws Exception {
        List<JobEntity> jobEntityList = jobService.quertListJobByPage(jobEntity);
        return getResult(jobEntity, jobEntityList);
    }

    /**
     * 暂停任务
     * @return
     */
    @PostMapping("pause")
    @ApiOperation(value = "暂停任务")
    public AjaxResult pauseJob(JobEntity jobEntity) throws Exception {
        jobService.pauseJob(jobEntity);
        return AjaxResult.success();
    }

    /**
     * 恢复任务
     * @return
     */
    @PostMapping("resume")
    @ApiOperation(value = "恢复任务")
    public AjaxResult resumeJob(JobEntity jobEntity) throws Exception {
        jobService.resumeJob(jobEntity);
        return AjaxResult.success();
    }

    /**
     * 执行任务
     * @return
     */
    @PostMapping("run")
    @ApiOperation(value = "执行任务")
    public AjaxResult runJob(JobEntity jobEntity) throws Exception {
        jobService.runJob(jobEntity);
        return AjaxResult.success();
    }

    /**
     * 删除任务
     * @return
     */
    @PostMapping("delete")
    @ApiOperation(value = "删除任务")
    public AjaxResult deleteJob(JobEntity jobEntity) throws Exception {
        jobService.deleteJob(jobEntity);
        return AjaxResult.success();
    }

    /**
     * 保存任务
     * @return
     */
    @PostMapping("save")
    @ApiOperation(value = "保存任务")
    public AjaxResult saveJob(JobEntity jobEntity) throws Exception {
        jobService.saveJob(jobEntity);
        return AjaxResult.success();
    }

    /**
     * 修改任务
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改任务")
    public AjaxResult updateJob(JobEntity jobEntity) throws Exception {
        jobService.updateJob(jobEntity);
        return AjaxResult.success();
    }
}
